package com.aididi.concurrent;

/**
 * @Auther: zx.xu
 * @Description:
 */
public class SynchronizedDemo3 {

    public static synchronized void methodone(){
        System.out.println("method 1 start");
        try {
            System.out.println("method 1 execute");
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("method 1 end");
    }

    public static synchronized void methodtwo(){
        System.out.println("method 2 start");
        try {
            System.out.println("method 2 execute");
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("method 2 end");
    }

    public static void main(String[] args) {
        final SynchronizedDemo2 demo1 = new SynchronizedDemo2();
        final SynchronizedDemo2 demo2 = new SynchronizedDemo2();
        new Thread(() -> {
            demo1.method1();
        }).start();

        new Thread(() -> {
            demo2.method2();
        }).start();
    }

}
